package cn.yuysaln.domain.activity.repository;

import cn.yuysaln.domain.activity.model.aggregate.CreatePartakeOrderAggregate;
import cn.yuysaln.domain.activity.model.aggregate.CreateQuotaOrderAggregate;
import cn.yuysaln.domain.activity.model.entity.*;
import cn.yuysaln.domain.activity.model.valobj.ActivitySkuStockKeyVO;

import java.util.Date;
import java.util.List;

public interface IActivityRepository {

    /**
     * 根据sku获取SKU实体
     * @param sku
     * @return
     */
    ActivitySkuEntity queryActivitySku(Long sku);

    /**
     * 活动ID查询具体活动信息
     * @param activityId
     * @return
     */
    ActivityEntity queryRaffleActivityByActivityId(Long activityId);

    ActivityCountEntity queryRaffleActivityCountByActivityCountId(Long activityCountId);


    void doSaveOrder(CreateQuotaOrderAggregate createQuotaOrderAggregate);

    void cacheActivitySkuStockCount(String key, Integer stockCount);

    /**
     *
     * @param sku
     * @param key 用于组成防止超卖加锁时的key
     * @param endDateTime 防止超卖加锁时间
     * @return
     */
    boolean subtractionActivitySkuStock(Long sku, String key, Date endDateTime);

    void activitySkuStockConsumeSendQueue(ActivitySkuStockKeyVO build);

    /**
     * 从sku库存队列取值
     * @return
     */
    ActivitySkuStockKeyVO takeQueueValue();

    /**
     * 情况sku库存队列
     */
    void clearQueueValue();

    /**
     * 指定sku库存减一
     * @param sku
     */
    void updateActivitySkuStock(Long sku);

    /**
     * 指定sku库存清零
     * @param sku
     */
    void clearActivitySkuStock(Long sku);

    ActivityAccountEntity queryActivityAccountByUserId(String userId, Long activityId);

    /**
     * 通过usrId+activityId+某月month 定位到月账户余额
     * @param userId
     * @param activityId
     * @param month
     * @return
     */
    ActivityAccountMonthEntity queryActivityAccountMonthByUserId(String userId, Long activityId, String month);

    /**
     * 通过usrId+activityId+某天day 定位到日账户余额
     * @param userId
     * @param activityId
     * @param day
     * @return
     */
    ActivityAccountDayEntity queryActivityAccountDayByUserId(String userId, Long activityId, String day);

    /**
     * 扣减活动抽奖额度，生成用户抽奖流水单
     * @param createPartakeOrderAggregate
     */
    void saveCreatePartakeOrderAggregate(CreatePartakeOrderAggregate createPartakeOrderAggregate);

    UserRaffleOrderEntity queryNoUsedRaffleOrder(PartakeRaffleActivityEntity partakeRaffleActivityEntity);

    List<ActivitySkuEntity> queryActivitySkuListByActivityId(Long activityId);

    Integer queryRaffleActivityAccountDayPartakeCount(Long activityId, String userId);
}
